fn convert_to_decimal(number_str: &str, from_radix: u64) -> u64 {
    let mut decimal_value = 0;
    let mut power = 0;
    for digit in number_str.chars().rev() {
        let value = match digit {
            '0'..='9' => digit as u64 - '0' as u64,
            'A'..='F' => digit as u64 - 'A' as u64 + 10,
            'a'..='f' => digit as u64 - 'a' as u64 + 10,
            _ => panic!("Invalid digit"),
        };
        decimal_value += value * from_radix.pow(power);
        power += 1;
    }
    decimal_value
}

fn convert_from_decimal(num: u64, to_radix: u64) -> String {
    let mut result = String::new();
    let mut num = num;
    while num > 0 {
        let remainder = num % to_radix;
        let digit = if remainder < 10 {
            (b'0' + remainder as u8) as char
        } else {
            ((b'a' - 10) + remainder as u8) as char
        };
        result.push(digit);
        num /= to_radix;
    }
    result.chars().rev().collect::<String>()
}

pub fn convert_base(num_str: &str, to_base: u32) -> String {
    let num_str = num_str.strip_suffix(")").unwrap();
    let splited: Vec<&str> = num_str.split("(").collect();
    let num = splited[0];
    let from_base = splited[1];
    let from_base = from_base.parse::<u64>().unwrap();
    let decimal = convert_to_decimal(num, from_base);
    let result = convert_from_decimal(decimal, to_base as u64);
    result
}
